package com.renzhebiao.lkang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.renzhebiao.lkang.comment.Need;
import com.renzhebiao.lkang.entity.BennerPO;
import com.renzhebiao.lkang.facade.BennerFacade;
import com.renzhebiao.lkang.master.ExecuteResult;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.BennerQuery;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 首页（轮播） 前端控制器
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@RestController
@RequestMapping("/benner")
@Api(tags = "首页（轮播）")
public class BennerController {

    @Autowired
    private BennerFacade bennerFacade;

    @ApiOperation(value = "新增首页（轮播）", notes = "新增首页（轮播）", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/add")
    @Need(token = true)
    public ExecuteResult<?> add(@RequestBody BennerPO po) {
        this.bennerFacade.add(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "修改首页（轮播）", notes = "修改首页（轮播）", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/edit")
    @Need(token = true)
    public ExecuteResult<?> edit(@RequestBody BennerPO po) {
        this.bennerFacade.edit(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "删除首页（轮播）", notes = "删除首页（轮播）", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/delete")
    @Need(token = true)
    public ExecuteResult<?> delete(@RequestBody Long id) {
        this.bennerFacade.delete(id);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "查询首页（轮播）列表", notes = "查询首页（轮播）列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/list")
    public ExecuteResult<?> getBennerList(@RequestBody BennerQuery param) {
        return ExecuteResult.ok(this.bennerFacade.getBennerList(param));
    }

    @ApiOperation(value = "查询新增首页（轮播）单条", notes = "查询新增首页（轮播）单条", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/get")
    public ExecuteResult<?> getBenner(@RequestBody Long id) {
        return ExecuteResult.ok(this.bennerFacade.getBenner(id));
    }

    @ApiOperation(value = "分页查询新增首页（轮播）", notes = "分页查询新增首页（轮播）", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/page")
    public ExecuteResult<?> getBennerByPage(@RequestBody PaginationDTO<BennerQuery, Void> paging) {
        return ExecuteResult.ok(this.bennerFacade.getBennerByPage(paging));
    }

}
